#!/bin/bash
#auther: welkin-cf
#date: 2020-7-5

read -p "input Repo's httpsURL for git:" -r repourl
gitpages=`echo $repourl | awk -F '[/.]' '{print $3}'` #支持GitHub平台
username=`echo $repourl | awk -F '[/.]' '{print $5}'`
reponame=`echo $repourl | awk -F '[/.]' '{print $6}'`

#rm -rf $reponame

git clone --recursive https://gitee.com/welkin-cf/hexo-starter-next.git $reponame \
        && cd $reponame \
        && rm -f .gitmodules LICENSE \
        && rm -rf .git themes/next/.git \
        && sed -i "s/gitee/$gitpages/g" _config.yml \ #增添对Github平台支持, 
        && sed -i "s/username/$username/g" _config.yml #需要修改_config.yml文件中的gitee主机为github 
		
if [ $username == $reponame ]
then
    sed -i "s#io/reponame#io#g" _config.yml
	sed -i "s/reponame//g" _config.yml
else
    sed -i "s/reponame/$reponame/g" _config.yml
fi

curl -O https://gitee.com/welkin-cf/hexo-starter/raw/master/package.json
curl -o source/_posts/hello-world.md https://gitee.com/welkin-cf/hexo-starter/raw/master/source/_posts/hello-world.md

cat > README.md << EOF
This is a website that 
Deployed on $gitpages Pages
and
Powered by Hexo & NexT
EOF

git init \
        && git config user.name "$reponame" \
        && git config user.email "email" \
        && git add . && git commit -m "init" \
		&& git remote add origin https://$gitpages.com/$username/$reponame.git 

git push -u origin master